﻿var relateVals = new Object();
$(initPage);
function initPage() {
	$("#checkItemDiv").attr("scrollTop", '48');//控制DIV滚动条
	$(".checkItem", "#checkList").click(function() {
		if($(this).hasClass("selectTD")) {
			return;
		}
	});
	$("#formulaDesc").text($("#check_12", "#checkList").attr("title"));
	$("#check_12", "#checkList").addClass("selectTD").find("img").attr("src","themes/comm/images/open.gif");
	
	
	var jobStatus = $("#jobStatus").val();
	//按扭不可操作
	if (jobStatus == '-2' || jobStatus == "0") {
		$("#reCheck,#btnEdit").attr("disabled", true);//不允许再次操作
	}
	
	//系统抽不到数据的项目，加*提示
	$(".menuChkItemId").each(function() {
		$("#i" + $(this).val()).prepend("<b style='color:blue' title='系统取不到数据'>* </b>");
	});
	
	$("#reCollect").click(function() {
		$("#reCollect").attr("disabled", true);//不允许再次操作
		$.post("m/submit_file/recollect", {
			checkName:"SE"
		}, function(data) {
			if ($.checkErrorMsg(data) ) {
				alert(data.msg.text);
				location.reload();
			} 
		}, "json");
	});
	$("#reCheck").click(function() {
		$("#reCheck").attr("disabled", true);//不允许再次操作
		$.post("m/submit_file/recheck", {
			checkName:"R12"
		}, function(data) {
			if ($.checkErrorMsg(data) ) {
				alert(data.msg.text);
				location.reload();
			} 
		}, "json");
	});
	queryNotPassed();
	
	//修改
	$("#btnEdit").click(function() {
		if ($.trim($("#chkId").val()) == "") {
			alert("无核对结果记录");
			return;
		}
		editElement("accSumAmt");
		editElement("bankAmt");
		editElement("reservesAmt");
		editElement("bailA13Amt");
		editElement("bailSdcAmt");
		editElement("arapAmt");
		editElement("settleAmt");
		editElement("fullComm");
		editElement("bankInterest");
		editElement("sdcCommAmt");
		editElement("secInterest");
		editElement("bankComm");
		editElement("sqtClearAmt");
		editElement("sqtStamptax");
		editElement("discAmt", false, true);
		editElement("note", true);
		countVal();
		
		$("#btnEdit").attr("disabled", true);
		$("#btnSave,#btnCancle").attr("disabled", false);
	});
	
	//取消修改
	$("#btnCancle").click(function() {
		cancleElement("accSumAmt");
		cancleElement("bankAmt");
		cancleElement("reservesAmt");
		cancleElement("bailA13Amt");
		cancleElement("bailSdcAmt");
		cancleElement("arapAmt");
		cancleElement("settleAmt");
		cancleElement("fullComm");
		cancleElement("bankInterest");
		cancleElement("sdcCommAmt");
		cancleElement("secInterest");
		cancleElement("bankComm");
		cancleElement("sqtClearAmt");
		cancleElement("sqtStamptax");
		cancleElement("discAmt");
		cancleElement("note");
		
		$("#btnSave,#btnCancle").attr("disabled", true);
		$("#btnEdit").attr("disabled", false);
	});
	//保存
	$("#btnSave").click(function() {
		if($.validInput($("#note").find("textarea"), "备注", false, "", 1000)){
			return false;
		}
		relateVals["accSumAmt"] = $.trim($("#accSumAmt").find("input").val());
		relateVals["bankAmt"] = $.trim($("#bankAmt").find("input").val());
		relateVals["reservesAmt"] = $.trim($("#reservesAmt").find("input").val());
		relateVals["bailA13Amt"] = $.trim($("#bailA13Amt").find("input").val());
		relateVals["bailSdcAmt"] = $.trim($("#bailSdcAmt").find("input").val());
		relateVals["arapAmt"] = $.trim($("#arapAmt").find("input").val());
		relateVals["settleAmt"] = $.trim($("#settleAmt").find("input").val());
		relateVals["fullComm"] = $.trim($("#fullComm").find("input").val());
		relateVals["bankInterest"] = $.trim($("#bankInterest").find("input").val());
		relateVals["sdcCommAmt"] = $.trim($("#sdcCommAmt").find("input").val());
		relateVals["secInterest"] = $.trim($("#secInterest").find("input").val());
		relateVals["bankComm"] = $.trim($("#bankComm").find("input").val());
		relateVals["sqtClearAmt"] = $.trim($("#sqtClearAmt").find("input").val());
		relateVals["sqtStamptax"] = $.trim($("#sqtStamptax").find("input").val());
		relateVals["discAmt"] = $.trim($("#discAmt").find("input").val());
		relateVals["note"] = $.trim($("#note").find("textarea").val());
		$.post("m/data_check/modifyr12", {
			id:$.trim($("#chkId").val()),
			relateId:$.trim($("#relateChkId").val()),
			accSumAmt:relateVals["accSumAmt"],
			bankAmt:relateVals["bankAmt"],
			reservesAmt:relateVals["reservesAmt"],
			bailA13Amt:relateVals["bailA13Amt"],
			bailSdcAmt:relateVals["bailSdcAmt"],
			arapAmt:relateVals["arapAmt"],
			settleAmt:relateVals["settleAmt"],
			fullComm:relateVals["fullComm"],
			bankInterest:relateVals["bankInterest"],
			sdcCommAmt:relateVals["sdcCommAmt"],
			secInterest:relateVals["secInterest"],
			bankComm:relateVals["bankComm"],
			sqtClearAmt:relateVals["sqtClearAmt"],
			sqtStamptax:relateVals["sqtStamptax"],
			discAmt:relateVals["discAmt"],
			note:relateVals["note"]
		}, function(data) {
			if ($.checkErrorMsg(data) ) {
				alert("操作成功");
				$("#relateChkId").val(data.msg.text);
				$("#btnCancle").click();
			} 
		}, "json");
		
	});
	
	$("#btnHist").click(function() {
		var url = BASE_PATH + "page/datacheck/check_r12_hist.jsp?busiDate=" + $("#busiDate").val();
		window.showModalDialog(url,"","dialogWidth:800px;dialogHeight:480px;help:no;center:yes;status:no");
	});
	
}

function editElement(eleId, textarea, disabled) {
	var obj = $("#" + eleId);
	var val = $.trim(obj.text());
	relateVals[eleId] = val;
	if (!val) {
		val = $.trim(obj.prev().text());
		val = val ? val : "0.00";
	}
	if(textarea) {
		obj.html("<textarea id='note' cols='45' rows='3'>" +  relateVals[eleId] + "</textarea>");
	} else {
		obj.html("<input type='text' value='" + val +"' " + (disabled ? "disabled" : "") + " onblur='checkVal(\"" + eleId +"\")'>");
	}
}

function cancleElement(eleId) {
	var obj = $("#" + eleId);
	obj.text(relateVals[eleId]);
}

//修改状态，失去焦点时检查格式，并重新统计
function checkVal(eleId) {
	var obj = $("#" + eleId).find("input");
	if($.validNumber(obj, "客户资金账户汇总余额", true, 999999999999999)){
		obj.select();
		return;
	}
	countVal();
}

//按公式计算差额
function countVal() {
	var sum = parseFloat($("#accSumAmt").find("input").val()) - 
		parseFloat($("#bankAmt").find("input").val()) - 
		parseFloat($("#reservesAmt").find("input").val()) - 
		parseFloat($("#bailA13Amt").find("input").val()) -
		parseFloat($("#bailSdcAmt").find("input").val()) -
		parseFloat($("#arapAmt").find("input").val()) -
		parseFloat($("#settleAmt").find("input").val()) +
		parseFloat($("#fullComm").find("input").val()) +
		parseFloat($("#bankInterest").find("input").val()) -
		parseFloat($("#sdcCommAmt").find("input").val()) -
		parseFloat($("#secInterest").find("input").val()) -
		parseFloat($("#bankComm").find("input").val()) -
		parseFloat($("#sqtClearAmt").find("input").val()) +
		parseFloat($("#sqtStamptax").find("input").val());
	$("#discAmt").find("input").val(sum.toFixed(2));
}

function changePage(url) {
	if(parseInt(url) < 10){
		url = "0"+url;
	}
	url = "m/data_check/initr"+url;
	location.href=BASE_PATH+url;
}

function getSettleAmt(dateType){
	var url = BASE_PATH + "m/data_check/querysettleAmtDetail?dateType=" + dateType + "&querySettleDate=" + $("#busiDate").val();
	window.open(url,"","width=1000, height=650,top=200, left=200,toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no");
}
